package com.smartcommunity.controller.sixEntity;

import com.smartcommunity.bean.constant.Constant;
import com.smartcommunity.bean.model.Result;
import com.smartcommunity.controller.BaseController;
import com.smartcommunity.log.interceptor.Log;
import com.smartcommunity.service.sixEntity.SixEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(value = "一标六实统计", tags = {"一标六实统计"})
@RestController
@RequestMapping(value = "/sixEntity")
@Slf4j
public class SixEntityController extends BaseController {
    @Autowired
    private SixEntityService sixEntityService;

    @ApiOperation(value = "查询一标六实分类统计信息", notes = "查询一标六实分类统计信息", httpMethod = "GET")
    @RequestMapping(value = "/getSixEntitySum",method = RequestMethod.GET)
    @Log(info = "查询一标六实分类统计信息",module = "一标六实",function = "查询")
    public Result getSixEntitySumByVillageCode(String villageCode) {
        long st=System.currentTimeMillis();
        Map<String, Object> param = new HashMap<>(1);
        param.put("villageCode", villageCode);
        Result result = sixEntityService.getSixEntitySum(param);
        long speedTime=System.currentTimeMillis()-st;
        log.info("查询一标六实分类统计信息，耗时:"+speedTime+"ms");
        return result;
    }

    @ApiOperation(value = "查询实有设备分类统计信息", notes = "查询实有设备分类统计信息", httpMethod = "GET")
    @RequestMapping(value = "/getDeviceSum",method = RequestMethod.GET)
    @Log(info = "查询实有设备分类统计信息",module = "一标六实",function = "查询")
    public Result getDeviceSum(String villageCode) {
        long st=System.currentTimeMillis();
        Map<String, Object> param = new HashMap<>(1);
        param.put("villageCode", villageCode);
        param.put("type", Constant.DEVICESTYPE);
        Result result = sixEntityService.getDeviceSum(param);
        long speedTime=System.currentTimeMillis()-st;
        log.info("查询实有设备分类统计信息，耗时:"+speedTime+"ms");
        return result;
    }


    @ApiOperation(value = "查询小区关联一标六实数据", notes = "查询小区关联一标六实数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "villageCode", value = "小区编号，多选时英文逗号分隔。若为空，后端根据用户权限圈定查询的小区范围", required = false),
            @ApiImplicitParam(name = "villageName", value = "小区名称", required = false),
            @ApiImplicitParam(name = "parentId", value = "行政区划ID，不支持多选", required = false),
            @ApiImplicitParam(name = "pageNumber", value = "当前页数", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = false)
    })
    @RequestMapping(value = "/pageSixEntitiesByVillage", method = RequestMethod.GET)
    @Log(info = "查询小区关联一标六实数据",module = "一标六实",function = "查询")
    public Result pageSixEntitiesByVillage(
            @RequestParam(required = false, name = "villageCode") String villageCode,
            @RequestParam(required = false, name = "villageName") String villageName,
            @RequestParam(required = false, name = "parentId") String parentId,
            @RequestParam(required = false, name = "pageNumber") String pageNumber,
            @RequestParam(required = false, name = "pageSize") String pageSize) {
        long st=System.currentTimeMillis();
        Map<String, Object> param = new HashMap<>(4);
        param.put("villageName", villageName);
        param.put("pageNumber", getPageNumber(pageNumber));
        param.put("pageSize", getPageSize(pageSize));
        param.put("villageCode", villageCode);
        Result result = sixEntityService.listSixEntityByVillage(param);
        long speedTime=System.currentTimeMillis()-st;
        log.info("查询小区关联一标六实数据，耗时:"+speedTime+"ms");
        return result;
    }

}
